<?php
require_once("../resources/commons.php");
require_once("../data/User.php");
require_once("admin_commons.php");
checkAdminRights();

$l_userId=base64_decode($_REQUEST["id"]);
$l_user=User::getFromPrimaryKey($l_userId);
$l_updateType=$_REQUEST["updateType"];

if($l_updateType == "activity"){
	if($l_user->getIsActive()){
		$l_user->setIsActive(false);
		$l_user->save();
		HTTP::redirect("manage_users.php");
	}else{
		$l_profileUpdateKey=getLongKey();
		$l_user->setProfileChangeKey($l_profileUpdateKey);
		$l_user->save();
		sendInvitation($l_user->getEmail(),$l_profileUpdateKey);
	}
}

if($l_updateType == "superadmin"){
	if($l_user->getIsActive() && $l_user->getIsAdmin()){
		$l_user->setIsAdmin(false);
		$l_user->save();
		HTTP::redirect("manage_users.php");
	}else{
		$l_user->setIsAdmin(true);
		$l_user->save();
		HTTP::redirect("manage_users.php");
	}
}

if($l_updateType == "financeadmin"){
	if($l_user->getIsActive() && $l_user->getIsFinanceAdmin()){
		$l_user->setIsFinanceAdmin(false);
		$l_user->save();
		HTTP::redirect("manage_users.php");
	}else{
		$l_user->setIsFinanceAdmin(true);
		$l_user->save();
		HTTP::redirect("manage_users.php");
	}
}

?>